package com.mask.mk.controller;


import com.mask.mk.service.CartService;
import com.mask.mk.util.JsonResult;
import com.mask.mk.vo.cart.AddCartRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 购物车 前端控制器
 * </p>
 *
 * @author joey
 * @since 2023-04-25
 */
@Api(tags = "购物车")
@RestController
@RequestMapping("/cart")
public class CartController {


    @Autowired
    private CartService cartService;


    @ApiOperation(value = "获取购物车列表")
    @PostMapping("/getCartList")
    public JsonResult getCartList(@RequestBody AddCartRequest addCartRequest){
        return cartService.getCartList(addCartRequest.getUserId());
    }

    @ApiOperation(value = "添加购物车列表")
    @PostMapping("/addCart")
    public JsonResult addCart(@RequestBody AddCartRequest addCartRequest){
        System.out.println(addCartRequest);
        return cartService.addCart(addCartRequest);
    }

    @ApiOperation(value = "删除购物车")
    @PostMapping("/delCart")
    public JsonResult delCart(@RequestBody AddCartRequest addCartRequest){
        System.out.println("购物车商品id:=> "+addCartRequest);
        return cartService.delCart(addCartRequest.getCartId());
    }

}

